import ajax from '@/utils/ajax.js'
import api from '@/config/api.js'

import { globalData } from '../config/globalData'
import baseUrl from '../baseUrl'

export default class Pay {
  // 创建微信支付订单
  static async createWxPayOrder (sn = [], paytype = 'MWEB') {
    let param = `token=${globalData.access_token}&pay_type=${paytype}`
    sn.map((item) => {
      param = param + `&order_sn[]=${item}`
    })

    let url = baseUrl.server + api.CREATE_WX_ORDER
    let res = await ajax.post(url, param)
    return res
  }

  static async wxPayOrderState (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    let url = baseUrl.server + api.MALL_ORDER_PayState
    param = Object.assign(defParam, param)
    let res = await ajax.post(url, param)
    return res
  }

  static async mallGroupOrderWin (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    let url = baseUrl.server + api.MALL_GROUP_ORDER_WIN
    param = Object.assign(defParam, param)
    let res = await ajax.post(url, param)
    return res
  }
}
